package o;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.Toast;
import com.huawei.appgallery.foundation.card.base.bean.BaseDistCardBean;
import com.huawei.appgallery.foundation.ui.framework.widget.dialog.dialogactivity.DialogActivity.a;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.listener.IServerCallBack;
import com.huawei.appmarket.service.appdetail.bean.detail.DetailHiddenBean;
import com.huawei.appmarket.service.pay.app.PayHmsEmbedActivity;
import com.huawei.appmarket.service.pay.app.bean.InitDownloadResponse;
import com.huawei.appmarket.service.pay.app.bean.OrderAppResponse;
import com.huawei.appmarket.service.pay.drm.bean.DrmCacheInfo;
import com.huawei.appmarket.service.pay.drm.bean.DrmItem;
import com.huawei.hms.support.api.entity.pay.HwPayConstant;
import com.huawei.hwid.core.constants.HwAccountConstants;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.security.GeneralSecurityException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import o.eck.c;
import o.ewm.n;

public class ecc {
    private String ʻ;
    private String ʼ = "0";
    private ecd ʽ = new ecd(this) {
        final /* synthetic */ ecc ˊ;

        {
            this.ˊ = r1;
        }

        public void ˊ(c cVar) {
            this.ˊ.ˊ(cVar);
        }

        public void ˏ(int i, int i2) {
            this.ˊ.ˎ(i, i2);
        }

        public void ˎ() {
            this.ˊ.ॱ();
        }

        public void ˋ(int i) {
            this.ˊ.ˏ(i);
        }

        public void ॱ() {
            this.ˊ.ˊ();
        }

        public void ˋ() {
            this.ˊ.ˋ();
        }
    };
    private final Activity ˊ;
    private djl ˋ;
    private BaseDistCardBean ˎ;
    private eck ˏ;
    private boolean ॱ = false;
    private String ॱॱ;
    private final IServerCallBack ᐝ = new IServerCallBack(this) {
        final /* synthetic */ ecc ॱ;

        {
            this.ॱ = r1;
        }

        public void prePostResult(BaseRequest o_cvu, ResponseBean responseBean) {
        }

        public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
            if (responseBean instanceof InitDownloadResponse) {
                this.ॱ.ॱ((ebx) o_cvu, (InitDownloadResponse) responseBean);
            } else if (responseBean instanceof OrderAppResponse) {
                this.ॱ.ˏ((OrderAppResponse) responseBean);
            } else {
                Logger.e("PayAgent", "StoreCallBack.notifyResult, unknown response type:" + responseBean.getClass().getSimpleName());
                this.ॱ.ˋ();
                this.ॱ.ˊ(c.Failed);
                Toast.makeText(ContentManager.getInstant().getContext(), ContentManager.getInstant().getContext().getString(n.ʼʿ), 0).show();
            }
        }
    };

    public ecc(Activity activity) {
        this.ˊ = activity;
        ˏ();
    }

    private void ˏ() {
        this.ॱ = true;
    }

    private void ˎ() {
        this.ʻ = null;
        this.ॱॱ = null;
    }

    public boolean ˎ(BaseDistCardBean baseDistCardBean, eck o_eck) {
        if (!ecf.ˏ().ˊ()) {
            if (Logger.ˎ()) {
                Logger.ˏ("PayAgent", "startPaying, inited=" + this.ॱ + ",appName:" + baseDistCardBean.v_());
            }
            if (this.ॱ) {
                this.ˎ = baseDistCardBean;
                if (Logger.ˎ()) {
                    Logger.ˏ("PayAgent", "init PayActivityTrigger and setSmOberver");
                }
                ecf.ˏ().ˎ("pageAgent", this.ʽ);
                ecf.ˏ().ˊ(true);
                ˎ();
                this.ˏ = o_eck;
                ॱ();
                ˏ(dgm.ˎ(this.ˊ));
                return true;
            }
            Toast.makeText(ContentManager.getInstant().getContext(), ContentManager.getInstant().getContext().getString(n.ʼʿ), 0).show();
            esu.ˎ("1", baseDistCardBean.ॱـ(), "004");
            return false;
        } else if (!Logger.ˎ()) {
            return false;
        } else {
            Logger.ˏ("PayAgent", "startPaying interrupted[" + baseDistCardBean.v_() + "], Other Pay processing is running");
            return false;
        }
    }

    private void ˏ(int i) {
        cvt o_ebx = new ebx(this.ˎ.ͺˏ(), this.ˎ.ˊˋ());
        o_ebx.ˎ(this.ˎ.ॱॱ());
        o_ebx.ˏ(this.ˎ.u_());
        o_ebx.setServiceType_(i);
        cfw.ˎ(o_ebx, this.ᐝ);
    }

    private void ॱ() {
        if (Logger.ˎ()) {
            Logger.ˏ("PayAgent", "startLoading");
        }
        if (!ActivityUtil.isAcitivtyNotValid(this.ˊ)) {
            if (this.ˋ == null) {
                this.ˋ = new djl(this.ˊ);
                this.ˋ.ˋ(this.ˊ.getString(n.ˊߴ));
                this.ˋ.setCancelable(false);
            }
            if (!this.ˋ.isShowing()) {
                this.ˋ.show();
            }
        } else if (Logger.ˎ()) {
            Logger.ˏ("PayAgent", "startLoading Failed , Activity hash not attached.");
        }
    }

    private void ˋ() {
        if (Logger.ˎ()) {
            Logger.ˏ("PayAgent", "stopLoading");
        }
        if (ActivityUtil.isAcitivtyNotValid(this.ˊ)) {
            if (Logger.ˎ()) {
                Logger.ˏ("PayAgent", "stopLoading Failed , Activity hash not attached.");
            }
        } else if (this.ˋ != null && this.ˋ.isShowing()) {
            this.ˋ.dismiss();
            this.ˋ = null;
        }
    }

    private boolean ˎ(InitDownloadResponse initDownloadResponse) {
        return initDownloadResponse.getRtnCode_() == -3 && (initDownloadResponse.ˊ() == 0 || initDownloadResponse.ˊ() == 2 || initDownloadResponse.ˊ() == 3);
    }

    private void ॱ(ebx o_ebx, InitDownloadResponse initDownloadResponse) {
        Context ˋ = ContentManager.getInstant().getContext();
        if (ˋ == null) {
            if (Logger.ˎ()) {
                Logger.ˏ("PayAgent", "processInitDownload interupted becauseof context is null");
            }
        } else if (initDownloadResponse.getResponseCode() != 0) {
            if (Logger.ˎ()) {
                Logger.ˏ("PayAgent", "processInitDownload result , res.responseCode is not OK");
            }
            ˋ();
            ˊ(c.Failed);
            Toast.makeText(ˋ, this.ˊ.getString(n.ʼʿ), 0).show();
        } else {
            Logger.ˏ("PayAgent", "processInitDownload:" + initDownloadResponse.toString());
            ˋ(initDownloadResponse, ˋ);
        }
    }

    private void ˋ(InitDownloadResponse initDownloadResponse, Context context) {
        if (ˎ(initDownloadResponse)) {
            if (Logger.ˎ()) {
                Logger.ˏ("PayAgent", "processInitDownload not ordered, will order app:" + this.ˎ.v_());
            }
            cvt o_eca = new eca(this.ˎ.u_(), this.ˎ.ˊˋ(), this.ˎ.ͺˏ(), dgm.ˎ(this.ˊ));
            if (this.ˎ instanceof DetailHiddenBean) {
                o_eca.accessId_ = dof.ʼ(((DetailHiddenBean) this.ˎ).ﹳ());
            }
            cfw.ˎ(o_eca, this.ᐝ);
            ebz.ॱ().ˋ(this.ˎ.ॱـ());
            esu.ˎ("2", this.ˎ.ॱـ(), "005");
        } else if (initDownloadResponse.getRtnCode_() == -3 && initDownloadResponse.ˊ() == 1) {
            ˋ();
            ˊ(c.Failed);
            Toast.makeText(context, context.getString(n.ʻﾟ), 0).show();
        } else if (initDownloadResponse.getRtnCode_() == 0 && initDownloadResponse.ˊ() == 4) {
            if (Logger.ˎ()) {
                Logger.ˏ("PayAgent", "processInitDownload has ordered , will continue process(open/download)");
            }
            ˋ();
            this.ʻ = initDownloadResponse.ˏ();
            ˊ(c.Success);
            ebz.ॱ().ˋ(this.ˎ.ॱـ(), this.ˎ.v_());
            ˋ(initDownloadResponse);
        } else if (initDownloadResponse.getRtnCode_() == -2) {
            ˋ();
            ˊ(c.Failed);
            Toast.makeText(context, context.getString(n.ˇ), 0).show();
            esu.ˎ("3", this.ˎ.ॱـ(), "006");
        } else if (initDownloadResponse.getRtnCode_() == 0 && initDownloadResponse.ˊ() == 5) {
            ॱ(initDownloadResponse);
        } else {
            ˋ();
            ˊ(c.Failed);
            Toast.makeText(context, context.getString(n.ʼʿ), 0).show();
        }
    }

    private void ˋ(InitDownloadResponse initDownloadResponse) {
        List<DrmItem> ˎ = initDownloadResponse.ˎ();
        if (!CollectCheck.isEmpty((List) ˎ)) {
            DrmCacheInfo drmCacheInfo = new DrmCacheInfo();
            ArrayList arrayList = new ArrayList();
            byte[] ˋ = evh.ˋ();
            for (DrmItem drmItem : ˎ) {
                drmCacheInfo.setDeveloperId(drmItem.ˎ());
                drmCacheInfo.setTs(drmItem.ˊ() + "");
                drmCacheInfo.setUserId(cev.ˋ(drmItem.ᐝ()));
                drmCacheInfo.setPkgName(drmItem.ॱ());
                try {
                    arrayList.add(ecs.ˎ(drmItem.ˋ(), drmItem.ˏ(), ˋ));
                } catch (InvalidKeyException e) {
                    Logger.ˋ("PayAgent", "processInitDownload InvalidKeyException");
                } catch (NoSuchAlgorithmException e2) {
                    Logger.ˋ("PayAgent", "processInitDownload NoSuchAlgorithmException");
                } catch (UnsupportedEncodingException e3) {
                    Logger.ˋ("PayAgent", "processInitDownload UnsupportedEncodingException");
                } catch (GeneralSecurityException e4) {
                    Logger.ˋ("PayAgent", "processInitDownload GeneralSecurityException");
                } catch (IllegalArgumentException e5) {
                    Logger.ˋ("PayAgent", "processInitDownload IllegalArgumentException");
                }
            }
            drmCacheInfo.setIv(dnk.ˏ(ˋ));
            drmCacheInfo.setSignList(arrayList);
            ecq.ॱ(drmCacheInfo);
        }
    }

    private void ˏ(OrderAppResponse orderAppResponse) {
        if (Logger.ˎ()) {
            Logger.ˏ("PayAgent", "processOrderApp:" + orderAppResponse.toString());
        }
        if (orderAppResponse.getResponseCode() == 0 && orderAppResponse.getRtnCode_() == 0) {
            this.ॱॱ = orderAppResponse.ˏ();
            ॱ(orderAppResponse);
            return;
        }
        ˋ();
        ˊ(c.Failed);
        Toast.makeText(ContentManager.getInstant().getContext(), ContentManager.getInstant().getContext().getString(n.ʼʿ), 0).show();
    }

    private void ˊ(c cVar) {
        if (this.ˏ != null) {
            if (cVar == c.Success) {
                if (TextUtils.isEmpty(this.ʻ)) {
                    Logger.e("PayAgent", "notifyPayResult, downloadUrl error! newUrl is null");
                    if (TextUtils.isEmpty(this.ʻ)) {
                        esu.ˎ(HwAccountConstants.TYPE_SINA, this.ˎ.ॱـ(), "008");
                    }
                } else {
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.append(this.ʻ);
                    stringBuilder.append("&sign=").append(HcridSession.ˋ().ˊ());
                    stringBuilder.append("&cno=").append(epl.ॱ().ˋ());
                    stringBuilder.append("&net=").append(doo.ˏ(ContentManager.getInstant().getContext()));
                    stringBuilder.append("&serviceType=").append(dgm.ˎ(this.ˊ));
                    this.ʻ = stringBuilder.toString();
                }
            }
            if (Logger.ˎ()) {
                Logger.ˏ("PayAgent", "notifyPayResult, appName:" + this.ˎ.v_() + ", PayResult:" + cVar);
            }
            ecf.ˏ().ˊ(false);
            this.ˏ.ˎ(cVar, this.ʻ, this.ʼ);
            ecf.ˏ().ˊ("pageAgent");
        } else if (Logger.ˎ()) {
            Logger.ˏ("PayAgent", "notifyPayResult, callback is null, appName:" + this.ˎ.v_() + ", PayResult:" + cVar);
        }
    }

    private void ˎ(int i, int i2) {
        ˎ(i, i2, this.ˎ.u_(), this.ˎ.ॱـ(), this.ˎ.ͺˏ());
    }

    private void ॱ(OrderAppResponse orderAppResponse) {
        Object ˊ = orderAppResponse.ˊ();
        if (TextUtils.isEmpty(ˊ)) {
            esu.ˎ(HwAccountConstants.TYPE_SECURITY_PHONE, this.ˎ.ॱـ(), "010");
        }
        Map ॱ = orderAppResponse.ॱ();
        ॱ.put(HwPayConstant.KEY_SIGN, orderAppResponse.ˎ());
        Bundle bundle = new Bundle();
        Serializable o_ecg = new ecg();
        o_ecg.ˎ(ॱ);
        bundle.putSerializable("pay_param", o_ecg);
        bundle.putString("pay_publickey", ˊ);
        bundle.putSerializable("pay_bean", this.ˎ);
        Intent intent = new Intent(this.ˊ, PayHmsEmbedActivity.class);
        intent.putExtras(bundle);
        if (Logger.ˎ()) {
            Logger.ˏ("PayAgent", "requestSDKPay startActivity PayHmsEmbedActivity");
        }
        this.ˊ.startActivity(intent);
    }

    private void ˊ() {
        String string = this.ˊ.getString(n.ʽꜞ);
        new a(this.ˊ, "PayFailedDialog").ˊ(n.ˏ).ॱ(this.ˊ.getString(n.ʻꞌ, new Object[]{string})).ˊ(-2, 8).ˎ();
        ˊ(c.Failed);
    }

    private void ˎ(int i, int i2, String str, String str2, String str3) {
        cvt o_ece = new ece();
        o_ece.ˎ(dof.ʼ(this.ॱॱ));
        o_ece.ॱ(i);
        o_ece.ˋ(dof.ʼ(str));
        o_ece.ॱ(dof.ʼ(str2));
        o_ece.ˏ(dof.ʼ(str3));
        o_ece.setServiceType_(i2);
        cfw.ˎ(o_ece, null);
    }

    private void ˏ(final InitDownloadResponse initDownloadResponse) {
        if (this.ˊ != null) {
            final cku ˏ = cku.ˏ(this.ˊ, cku.class, null, this.ˊ.getString(n.ʽˑ));
            ˏ.ˎ(this.ˊ);
            ˏ.ॱ(-1, this.ˊ.getResources().getString(n.ʼﾞ));
            ˏ.ॱ(new cks(this) {
                final /* synthetic */ ecc ˏ;

                public void enableNetworking() {
                    ˏ.dismiss();
                    if (Logger.ˎ()) {
                        Logger.ˏ("PayAgent", "processInitDownload has familysharing , will continue process(open/download)");
                    }
                    this.ˏ.ʻ = initDownloadResponse.ˏ();
                    this.ˏ.ʼ = "1";
                    this.ˏ.ˊ(c.Success);
                    ebz.ॱ().ˋ(this.ˏ.ˎ.ॱـ(), this.ˏ.ˎ.v_());
                    this.ˏ.ˋ(initDownloadResponse);
                }

                public void upgrade() {
                    ˏ.dismiss();
                    this.ˏ.ˊ(c.Failed);
                }

                public void ˋ() {
                }
            });
        } else if (Logger.ˎ()) {
            Logger.ˏ("PayAgent", "FamilyShareDialog fail becauseof context is null");
        }
    }

    private void ॱ(InitDownloadResponse initDownloadResponse) {
        ˋ();
        boolean ˏ = erz.ˏ(this.ˊ, this.ˎ.ॱـ());
        if (csv.ˋ().ॱ() || ˏ) {
            this.ʻ = initDownloadResponse.ˏ();
            ˊ(c.Success);
            this.ʼ = "1";
            ebz.ॱ().ˋ(this.ˎ.ॱـ(), this.ˎ.v_());
            ˋ(initDownloadResponse);
            return;
        }
        ˏ(initDownloadResponse);
    }
}
